/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IA;

import java.util.*;
/**
 *
 * @author Jeremy
 */
public class CookItem implements ClockObserverInterface {
    private int TableID;
    private int TimeLeft;
    private int TotalCookTime; //time in queue + prep time
    private String Name;
    
    public CookItem(int PrepTime, int TableID, String Name) {
        TimeLeft = PrepTime;
        this.Name = Name;
        this.TableID = TableID;
    }
    
    public boolean Cook() {
        if(--TimeLeft == 0) return true;
        else return false;
    }
    public void setPrepTime(int t) {TimeLeft = t;}
    public int getPrepTime() {return TimeLeft;}
    public String getName() {return Name;}
    public int getTableID() {return TableID;}
    
    public Integer getTotalCookTime() {return TotalCookTime;}
    
    public static Comparator getLowestFirstPrepTimeComparator() {
        return new LowestFirstPrepTimeComparator();
    }
    
    public static Comparator getHighestFirstPrepTimeComparator() {
        return new HighestFirstPrepTimeComparator();
    }

    public static Comparator getNameComparator() {
        return new NameComparator();
    }

    @Override
    public void clockTick() {
        TotalCookTime++;
    }
    
    private static class LowestFirstPrepTimeComparator implements Comparator {

        @Override
        public int compare(Object o1, Object o2) {
            CookItem c1 = (CookItem)o1; CookItem c2 = (CookItem)o2;
            if(c1.getPrepTime() < c2.getPrepTime()) return -1;
            else {
                if(c1.getPrepTime() == c2.getPrepTime()) return 0;
                else return 1;
            }
        }

    }
    private static class HighestFirstPrepTimeComparator implements Comparator {

        @Override
        public int compare(Object o1, Object o2) {
            CookItem c1 = (CookItem)o1; CookItem c2 = (CookItem)o2;
            if(c1.getPrepTime() > c2.getPrepTime()) return -1;
            else {
                if(c1.getPrepTime() == c2.getPrepTime()) return 0;
                else return 1;
            }
        }

    }
    
    private static class NameComparator implements Comparator {

        @Override
        public int compare(Object o1, Object o2) {
            CookItem c1 = (CookItem)o1; CookItem c2 = (CookItem)o2;
            return String.CASE_INSENSITIVE_ORDER.compare(c1.getName(), c2.getName());
        }
        
    }
    
}
